import pytest

from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By

class TestCase(object):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://10.215.56.131:8002/#/ai-home")
        self.driver.maximize_window()


    #@classmethod
    #def setUpClass(cls)->None:
        #cls.driver = webdriver.Chrome()
        #cls.driver.get("http://10.215.56.131:8002/#/ai-home")
        #cls.driver.maximize_window()

    #正确用户名 错误密码
    @pytest.mark.undo
    def testLogin(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://10.215.56.131:8002/#/ai-home")
        self.driver.maximize_window()
        username = "test"
        password = "12345"
        expected = "用户名或密码错误"
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="guimi-home"]/body/section[1]/div/button/span').click()
        sleep(1)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[1]/div/div/input').send_keys(username)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').clear()
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[2]/div/div/input').send_keys(password)
        self.driver.find_element(By.XPATH,'//*[@id="pane-STANDARD"]/div/div[4]/button/span').click()
        sleep(2)
        actual = self.driver.find_element(By.XPATH,"/html/body/div[2]/p")
        text = actual.text
        assert text == expected
if __name__ == '__main__':
    #case = TestCase()
    #case.login("test","123456","用户名或密码错误")
    pytest.main(["testlogin.py"])